package com.torry.workflow.service.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.torry.workflow.api.user.entity.Role;
import com.torry.workflow.api.user.entity.UserRole;
import com.torry.workflow.service.user.mapper.RoleMapper;
import com.torry.workflow.service.user.mapper.UserRoleMapper;
import com.torry.workflow.service.user.service.IRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author torry
 * @since 2021-12-25
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    @Resource
    private UserRoleMapper userRoleMapper;

    @Override
    public List<Integer> getRoleIdsByUserId(Integer userId) {
        List<UserRole> list = userRoleMapper.selectList(new QueryWrapper<UserRole>().eq("deleted", 0).eq("user_id", userId));
        return list.stream().map(userRole -> userRole.getRoleId()).collect(Collectors.toList());
    }
}
